package com.example.springscriptengine.js;

import javax.script.ScriptEngineManager;

/**
 * @program: cancan-java-share
 * @description: js测试
 * @author: czchen
 * @date: 2022-10-17 10:12:44
 */
public class JavaScriptTest {

    /**
     * 步骤1：定义js解析工具
     * 步骤2：定义js脚本
     * 步骤3：执行js脚本
     *
     * @param args
     */
    public static void main(String[] args) {
        long l = System.currentTimeMillis();
        String script = "function run(cat){age=cat.age1+cat.age2;return cat.name+age}";
        Cat cat = new Cat();
        cat.setAge1(5);
        cat.setAge2(2);
        cat.setName("大猫");
        Object o = JsUtil.jsRun("run", script, cat);
        System.out.println(o);
    }
}
